/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.beans.*;
import java.io.Serializable;

/**
 *
 * @author Carlos S. Moreno <CarlosS.Moreno@gmail.com>
 */
public class iCard extends Canvas implements Serializable {
    
    public static final String PROP_CARD_NAME = "cardName";
    private String cardName;
    private int HEIGHT, WIDTH, CORNER_ARC;
    private PropertyChangeSupport propertySupport;
    
    public iCard() {
        this(500);
    }
    
    public iCard(int height) {
        setNewHeight(height);
        propertySupport = new PropertyChangeSupport(this);
    }

    public void setNewHeight(int height) {
        HEIGHT = height-4;
        WIDTH = (int)(height*(0.6895));
        CORNER_ARC = (int)(height*(0.05));
    }
    
    public String getSampleProperty() {
        return cardName;
    }
    
    public void setSampleProperty(String value) {
        String oldValue = cardName;
        cardName = value;
        propertySupport.firePropertyChange(PROP_CARD_NAME, oldValue, cardName);
    }
    
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    
    public void paint(Graphics g) {
        //Main Card Color
        g.setColor(Color.black);
        g.fillRoundRect(2, 2, WIDTH, HEIGHT, CORNER_ARC, CORNER_ARC);
        g.setColor(Color.white);
        g.fillRoundRect(2+(int)(WIDTH*(0.02)), (int)(HEIGHT*(0.02)), WIDTH-(int)(WIDTH*(0.04)), (int)(HEIGHT*(0.2)), CORNER_ARC, CORNER_ARC);
        g.setColor(Color.black);        
        g.fillRect(2, (int)(HEIGHT*(0.07)), WIDTH, (int)(HEIGHT*(0.2)));
        
        //PathWay 1st Color
        g.setColor(Color.blue);
        g.fillRoundRect(2+(int)(WIDTH*(0.02)), (int)(HEIGHT*(0.07)), WIDTH-(int)(WIDTH*(0.04)), HEIGHT-(int)(HEIGHT*(0.08)), CORNER_ARC, CORNER_ARC);
        g.fillRect(2+(int)(WIDTH*(0.02)), (int)(HEIGHT*(0.07)), WIDTH-(int)(WIDTH*(0.04)), (int)(HEIGHT*(0.3)));
        
        //PathWay 2nd Color
        g.setColor(Color.green);
        g.fillRoundRect(2+(int)(WIDTH*(0.05)), (int)(HEIGHT*(0.07)), WIDTH-(int)(WIDTH*(0.1)), HEIGHT-(int)(HEIGHT*(0.08)), CORNER_ARC, CORNER_ARC);
        g.fillRect(2+(int)(WIDTH*(0.05)), (int)(HEIGHT*(0.07)), WIDTH-(int)(WIDTH*(0.1)), (int)(HEIGHT*(0.3)));
        
        //ImageBox
        g.setColor(Color.WHITE);
        g.fillRoundRect(2+(int)(WIDTH*(0.08)), (int)(HEIGHT*(0.11)), WIDTH-(int)(WIDTH*(0.16)), (int)(HEIGHT*(0.5)), CORNER_ARC, CORNER_ARC);
        
        //TextBox
        g.setColor(Color.WHITE);
        g.fillRoundRect(2+(int)(WIDTH*(0.08)), (int)(HEIGHT*(0.62)), WIDTH-(int)(WIDTH*(0.16)), (int)(HEIGHT*(0.35)), CORNER_ARC, CORNER_ARC);      
        
        //Cost
        g.setColor(Color.black);
        g.fillOval(2+(int)(WIDTH*(0.04)), 2+(int)(HEIGHT*(0.04)), (int)(WIDTH*(0.11)), (int)(WIDTH*(0.11)));
        g.setColor(Color.white);
        g.fillOval(2+(int)(WIDTH*(0.045)), 2+(int)(HEIGHT*(0.042)), (int)(WIDTH*(0.1)), (int)(WIDTH*(0.1)));
        
        //Streng
        g.setColor(Color.black);
        g.fillOval(2+(int)(WIDTH*(0.04)), 2+(int)(HEIGHT*(0.9)), (int)(WIDTH*(0.11)), (int)(WIDTH*(0.11)));
        g.setColor(Color.red);
        g.fillOval(2+(int)(WIDTH*(0.045)), 2+(int)(HEIGHT*(0.905)), (int)(WIDTH*(0.1)), (int)(WIDTH*(0.1)));
        
        //Life
        g.setColor(Color.black);
        g.fillOval(2+(int)(WIDTH*(0.86)), 2+(int)(HEIGHT*(0.9)), (int)(WIDTH*(0.11)), (int)(WIDTH*(0.11)));
        g.setColor(Color.blue);
        g.fillOval(2+(int)(WIDTH*(0.865)), 2+(int)(HEIGHT*(0.905)), (int)(WIDTH*(0.1)), (int)(WIDTH*(0.1)));
        
        //CARD TEXTS
        String cardName = "Barahai alfa";
        
        g.setColor(Color.black);
        int typeFontSize = (int)(HEIGHT*(0.04));
        int numbersFontSize = (int)(HEIGHT*(0.055));
        int lineSize = (int)(HEIGHT*(0.05));
        int descriptionFontSize = (int)(HEIGHT*(0.035));
        int nameFontSize;        
        if (cardName.length() > 18) nameFontSize = (int)(HEIGHT*(0.04));
        else nameFontSize = (int)(HEIGHT*(0.05));
            
        
        //Card Name        
        g.setFont(new Font(Font.MONOSPACED, Font.CENTER_BASELINE, nameFontSize));
        g.drawString(cardName, (int)(WIDTH*(0.15)), (int)(HEIGHT*(0.063)));
        
        //Type
        g.setFont(new Font(Font.MONOSPACED, Font.BOLD, typeFontSize));
        g.drawString("Aliado único", (int)(WIDTH*(0.155)), (int)(HEIGHT*(0.1)));
        
        //Cost
        g.setFont(new Font(Font.MONOSPACED, Font.BOLD, numbersFontSize));        
        g.drawString("X", (int)(WIDTH*(0.08)), (int)(HEIGHT*(0.1)));
        
        //Attack
        g.drawString("X", (int)(WIDTH*(0.08)), (int)(HEIGHT*(0.96)));
        
        //Defense
        g.drawString("X", (int)(WIDTH*(0.90)), (int)(HEIGHT*(0.96)));
        
        //Description
        g.setFont(new Font(Font.MONOSPACED, Font.CENTER_BASELINE, descriptionFontSize));  
        String description = "La Sirena de voz tranquila no puede recivir daño de aliados.";
        int line = 0;
        while(description.length() > 0)
        {
            if (description.length() > 27){
            g.drawString(description.substring(0, 27),
                (int)(WIDTH*(0.1)), (int)(HEIGHT*(0.66))+line*lineSize);
            description = description.substring(27);}
            else{
                g.drawString(description,
                (int)(WIDTH*(0.1)), (int)(HEIGHT*(0.66))+line*lineSize);
                description = "";
            }
            line++;
        }        
     }
    
}
